package cn.tedu.flower.manage.content.dao.persist.repository.impl;

import cn.tedu.flower.manage.common.pojo.vo.PageData;
import cn.tedu.flower.manage.common.util.PageInfoToPageDataConverter;
import cn.tedu.flower.manage.content.dao.persist.mapper.FadebackMapper;
import cn.tedu.flower.manage.content.dao.persist.repository.IFadebackRepository;
import cn.tedu.flower.manage.content.pojo.entity.Fadeback;
import cn.tedu.flower.manage.content.pojo.vo.FadebackListItemVO;
import cn.tedu.flower.manage.content.pojo.vo.FadebackStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Slf4j
@Repository
public class FadebackRepositoryImpl implements IFadebackRepository {
    @Autowired
    FadebackMapper fadebackMapper;

    @Override
    public int insert(Fadeback fadeback) {
        log.debug("开始执行【插入反馈信息】的数据访问，参数：{}", fadeback);
        return fadebackMapper.insert(fadeback);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据id删除反馈信息】的数据访问，参数：{}", id);
        return fadebackMapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Collection<Long> idList) {
        log.debug("开始执行【根据id删除反馈信息】的数据访问，参数：{}", idList);
        return fadebackMapper.deleteBatchIds(idList);
    }

    @Override
    public int update(Fadeback fadeback) {
        log.debug("开始执行【根据id修改反馈信息】的数据访问，参数：{}", fadeback);
        return fadebackMapper.updateById(fadeback);
    }

    @Override
    public int count() {
        log.debug("开始执行【查看反馈信息条数】的数据访问，参数：{}");
        return fadebackMapper.selectCount(null);
    }

    @Override
    public FadebackStandardVO selectById(Long id) {
        log.debug("开始执行【根据ID查询反馈信息】的数据访问，参数：{}", id);
        return fadebackMapper.selectById(id);
    }

    @Override
    public PageData<FadebackListItemVO> selectAll(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询商品列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum,pageSize);
        List<FadebackListItemVO> list = fadebackMapper.selectAll();
        PageInfo<FadebackListItemVO>pageInfo=new PageInfo<>(list);
        PageData<FadebackListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
